from pynput import keyboard
from time import time

class KeyboardListener:
    def __init__(self, callback):
        self.last_press_time = 0
        self.callback = callback
        self.listener = keyboard.Listener(on_press=self.on_press)
        self.listener.start()

    def on_press(self, key):
        try:
            if key == keyboard.Key.ctrl_l:
                current_time = time()
                if current_time - self.last_press_time <= 0.5:
                    self.callback()
                self.last_press_time = current_time
        except AttributeError:
            pass